package net.sareweb.acab.session;

import net.sareweb.acab.entity.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("suggestionHome")
public class SuggestionHome extends EntityHome<Suggestion> {

	@In(create = true)
	SuggestioninfoHome suggestioninfoHome;
	@In(create = true)
	RequestHome requestHome;

	public void setSuggestionIdSuggestion(Integer id) {
		setId(id);
	}

	public Integer getSuggestionIdSuggestion() {
		return (Integer) getId();
	}

	@Override
	protected Suggestion createInstance() {
		Suggestion suggestion = new Suggestion();
		return suggestion;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Suggestioninfo suggestioninfo = suggestioninfoHome.getDefinedInstance();
		if (suggestioninfo != null) {
			getInstance().setSuggestioninfo(suggestioninfo);
		}
		Request request = requestHome.getDefinedInstance();
		if (request != null) {
			getInstance().setRequest(request);
		}
	}

	public boolean isWired() {
		if (getInstance().getSuggestioninfo() == null)
			return false;
		if (getInstance().getRequest() == null)
			return false;
		return true;
	}

	public Suggestion getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
